﻿using System;
using System.Collections.Generic;
using SizeboxUI;
using TMPro;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;

// Token: 0x0200038A RID: 906
public class MenuController : MonoBehaviour
{
	// Token: 0x060017A5 RID: 6053 RVA: 0x000963FD File Offset: 0x000945FD
	private void Awake()
	{
		this.stateManager = StateManager.instance;
		UnityEngine.Object.FindObjectOfType<TextMeshProUGUI>().text = "Sizebox v" + global::Version.GetVersionNumber();
		UnityEngine.Object.FindObjectOfType<Canvas>().scaleFactor = GlobalPreferences.UIScale.value;
	}

	// Token: 0x060017A6 RID: 6054 RVA: 0x00096438 File Offset: 0x00094638
	protected void Start()
	{
		Cursor.visible = true;
		Cursor.lockState = CursorLockMode.None;
		this.modelManager = IOManager.Instance;
		MenuController.menuController = this;
		this.sceneLoader = UnityEngine.Object.FindObjectOfType<SceneLoader>();
		if (!this.sceneLoader)
		{
			Debug.LogError("Can't find the Scene Loader on the scene.");
		}
		this.listChar = this.modelManager.GetPlayerModels();
		this.listStages = this.sceneLoader.GetSceneList();
		this.activeChar = 0;
		this.activeScene = 0;
		this.engineToggle.isOn = GlobalPreferences.UseNewRenderEngine.value;
		this.engineToggle.onValueChanged.AddListener(new UnityAction<bool>(this.OnEngineToggle));
		this.settingsUI = UnityEngine.Object.Instantiate<GameObject>(Resources.Load<GameObject>("UI/PauseMenu"));
		this.settingsUI.AddComponent<MainMenuSettingsController>().MainMenu = MenuController.menuController;
		this.settingsUI.transform.SetParent(this.charUI.transform.parent, false);
		this.settingsUI.SetActive(false);
	}

	// Token: 0x060017A7 RID: 6055 RVA: 0x0009653F File Offset: 0x0009473F
	protected void OnDestroy()
	{
		if (MenuController.menuController != null)
		{
			MenuController.menuController = null;
		}
	}

	// Token: 0x060017A8 RID: 6056 RVA: 0x00096557 File Offset: 0x00094757
	private void OnEngineToggle(bool value)
	{
		GlobalPreferences.UseNewRenderEngine.value = value;
	}

	// Token: 0x060017A9 RID: 6057 RVA: 0x00096564 File Offset: 0x00094764
	public void OnStartClick()
	{
		this.stateManager.gameSettings.multiplayer = false;
	}

	// Token: 0x060017AA RID: 6058 RVA: 0x00096577 File Offset: 0x00094777
	public void OnLANClick()
	{
		this.stateManager.gameSettings.multiplayer = true;
		this.charUI.gameObject.SetActive(true);
		this.menuUI.gameObject.SetActive(false);
	}

	// Token: 0x060017AB RID: 6059 RVA: 0x000965AC File Offset: 0x000947AC
	public void OnLoadClick()
	{
		this.loadUI.gameObject.SetActive(true);
		this.menuUI.gameObject.SetActive(false);
	}

	// Token: 0x060017AC RID: 6060 RVA: 0x000965D0 File Offset: 0x000947D0
	public void OnSettingsClick()
	{
		this.settingsUI.SetActive(true);
		this.menuUI.gameObject.SetActive(false);
	}

	// Token: 0x060017AD RID: 6061 RVA: 0x000965EF File Offset: 0x000947EF
	public void OnExitClick()
	{
		Application.Quit();
	}

	// Token: 0x060017AE RID: 6062 RVA: 0x000965F6 File Offset: 0x000947F6
	public void switchNextChar()
	{
		this.activeChar = (this.listChar.Count + (this.activeChar + 1)) % this.listChar.Count;
	}

	// Token: 0x060017AF RID: 6063 RVA: 0x0009661E File Offset: 0x0009481E
	public void switchPreviousChar()
	{
		this.activeChar = (this.listChar.Count + (this.activeChar - 1)) % this.listChar.Count;
	}

	// Token: 0x060017B0 RID: 6064 RVA: 0x00096646 File Offset: 0x00094846
	public GameObject getActiveChar()
	{
		return this.listChar[this.activeChar];
	}

	// Token: 0x060017B1 RID: 6065 RVA: 0x00096659 File Offset: 0x00094859
	public void switchNextScene()
	{
		this.activeScene = (this.listStages.Count + (this.activeScene + 1)) % this.listStages.Count;
	}

	// Token: 0x060017B2 RID: 6066 RVA: 0x00096681 File Offset: 0x00094881
	public void switchPreviousScene()
	{
		this.activeScene = (this.listStages.Count + (this.activeScene - 1)) % this.listStages.Count;
	}

	// Token: 0x060017B3 RID: 6067 RVA: 0x000966A9 File Offset: 0x000948A9
	public SceneLoader.SceneInfo getActiveSceneData()
	{
		return this.listStages[this.activeScene];
	}

	// Token: 0x060017B4 RID: 6068 RVA: 0x000966BC File Offset: 0x000948BC
	private void Update()
	{
		if ((Input.GetKey(KeyCode.RightControl) || Input.GetKey(KeyCode.LeftControl)) && (Input.GetKey(KeyCode.RightAlt) || Input.GetKey(KeyCode.LeftAlt)) && Input.GetKeyDown(KeyCode.R))
		{
			GlobalPreferences.UIScale.value = 1f;
			GameObject.Find("MainCanvas(Clone)").GetComponent<Canvas>().scaleFactor = GlobalPreferences.UIScale.value;
		}
	}

	// Token: 0x040019EA RID: 6634
	private static MenuController menuController;

	// Token: 0x040019EB RID: 6635
	private List<GameObject> listChar;

	// Token: 0x040019EC RID: 6636
	private IOManager modelManager;

	// Token: 0x040019ED RID: 6637
	private int activeChar;

	// Token: 0x040019EE RID: 6638
	private int activeScene;

	// Token: 0x040019EF RID: 6639
	private List<SceneLoader.SceneInfo> listStages;

	// Token: 0x040019F0 RID: 6640
	private SceneLoader sceneLoader;

	// Token: 0x040019F1 RID: 6641
	public Canvas charUI;

	// Token: 0x040019F2 RID: 6642
	public Canvas loadUI;

	// Token: 0x040019F3 RID: 6643
	public Canvas menuUI;

	// Token: 0x040019F4 RID: 6644
	public GameObject settingsUI;

	// Token: 0x040019F5 RID: 6645
	public Toggle engineToggle;

	// Token: 0x040019F6 RID: 6646
	private StateManager stateManager;

	// Token: 0x0200038B RID: 907
	[Serializable]
	public class StageData
	{
		// Token: 0x040019F7 RID: 6647
		public string scene;

		// Token: 0x040019F8 RID: 6648
		public Sprite thumbnail;
	}
}
